package pers.wq.controller.admin;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.views.jsp.ui.FormTag;

import pers.wq.controller.PublicListAction;
import pers.wq.model.MyModel;
import pers.wq.model.bean.Admin;
import pers.wq.model.bean.BaseBean;
import pers.wq.model.bean.College;
import pers.wq.model.bean.Lesson;
import pers.wq.model.bean.LessonCat;
import pers.wq.model.bean.Score;
import pers.wq.model.bean.ScoreCat;
import pers.wq.model.bean.Student;
import pers.wq.model.bean.Time;
import pers.wq.model.bean.User;
import pers.wq.util.TagManager;

public class IndexAction extends PublicListAction{
	public static String ADMIN_LOGIN_TAG = "ADMIN_LOGIN";
	private Admin user;
	private College college;
	private User teacher;
	private LessonCat lessonCat;
	private Lesson lesson;
	private ScoreCat scoreCat;
	private Score score;
	private Time time;
	private Student student;
	private BaseBean[] objs;
	
	
	public IndexAction() {
		// TODO Auto-generated constructor stub
		super("admin");
		setLoginTag(ADMIN_LOGIN_TAG);
		System.out.println("admin.IndexAction __constructor");
	}
	
	public String great() throws Exception{
		return this.delete();
	}
	@Override
	public String formTag() {
		// TODO Auto-generated method stub
		return TagManager.formTag(getDataListId(),"admin",getMethod());
	}
	@Override
	public Map<String, String> mapTag() {
		// TODO Auto-generated method stub
		return _mapTag(objs);
	}
	@Override
	public String add() throws Exception {
		// TODO Auto-generated method stub
		BaseBean[] objs = {college,teacher,lessonCat,lesson,scoreCat,score,time,student};
		String reStr = this._add(objs);
		return reStr == SUCCESS ? CHAIN : ERROR;
	}
	@Override
	public String se() throws Exception {
		// TODO Auto-generated method stub
		objs = new BaseBean[]{college,teacher,lessonCat,lesson,scoreCat,score,time,student};
		String reStr = _se(objs)  == EA ? super.se() : ERROR;
		return reStr;
	}
	@Override
	public String sa() throws Exception {
		// TODO Auto-generated method stub
		objs = new BaseBean[]{college,teacher,lessonCat,lesson,scoreCat,score,time,student};
		return super.sa();
	}
	@Override
	public String update() throws Exception {
		// TODO Auto-generated method stub
		BaseBean[] objs = {college,teacher,lessonCat,lesson,scoreCat,score,time,student};
		String reStr = this._update(objs);
		return reStr == SUCCESS ? CHAIN : ERROR;
	}
	
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		BaseBean[] objs = {college,teacher,lessonCat,lesson,scoreCat,score,time,student};
		System.out.println("delete in");
		try{
			if(this._delete(objs).equals(SUCCESS)){
				this.setJsonMapSuccess("Delete success!");
			}else{
				this.setJsonMapError("Delete error!");
			}
		}catch(Exception e){
			this.setJsonMapError("Delete error");
		}
		System.out.println(jsonMap);
		return JSON;
	}
	
	public String login() {
		String reStr = ERROR;
		if(user.isRight()) {
			this.loginSession();
			reStr = SUCCESS;
		}
		return reStr;
	}
	public String index() {
		return SUCCESS;
	}
	public Admin getUser() {
		return user;
	}
	public void setUser(Admin user) {
		this.user = user;
	}
	public College getCollege() {
		return college;
	}
	public void setCollege(College college) {
		this.college = college;
	}
	public User getTeacher() {
		return teacher;
	}
	public void setTeacher(User teacher) {
		this.teacher = teacher;
	}
	public LessonCat getLessonCat() {
		return lessonCat;
	}
	public void setLessonCat(LessonCat lessonCat) {
		this.lessonCat = lessonCat;
	}
	public Lesson getLesson() {
		return lesson;
	}
	public void setLesson(Lesson lesson) {
		this.lesson = lesson;
	}
	public ScoreCat getScoreCat() {
		return scoreCat;
	}
	public void setScoreCat(ScoreCat scoreCat) {
		this.scoreCat = scoreCat;
	}
	public Score getScore() {
		return score;
	}
	public void setScore(Score score) {
		this.score = score;
	}
	public Time getTime() {
		return time;
	}
	public void setTime(Time time) {
		this.time = time;
	}
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
}
